#include <ddt.h>

void dd_mesh_draw(struct dd_mesh *m) {
	glLoadMatrixf( dd_da_get( dd_cam, dd_cam->elements-1 ) );
	/* pass data to arrays */
	int i = 0;
	while (m->attr[i] != 0) {
		switch (m->attr[i]) {
			case DD_MESH_POS:
				glEnableClientState(GL_VERTEX_ARRAY);
				glVertexPointer(3, GL_FLOAT, 0, ((void**) m->ar)[i]);
				break;
			case DD_MESH_COL:
				glEnableClientState(GL_COLOR_ARRAY);
				glColorPointer(3, GL_FLOAT, 0, ((void**) m->ar)[i]);
				break;
		}
		i++;
	}

	/* draw arrays */
	glDrawArrays(GL_TRIANGLES, 0, m->vcount);

	/* disable data from arrays */
	i = 0;
	while (m->attr[i] != 0) {
		switch (m->attr[i]) {
			case DD_MESH_POS:
				glDisableClientState(GL_VERTEX_ARRAY);
				break;
			case DD_MESH_COL:
				glDisableClientState(GL_COLOR_ARRAY);
				break;
		}
		i++;
	}
}

